//
//  UIViewController+Common.m
//  VET
//
//  Created by Lam BG on 2018/7/12.
//  Copyright © 2018年 YZ. All rights reserved.
//

#import "UIViewController+Common.h"
#import "UIViewController+BGTransition.h"

#import "TBCityIconFont.h"

#import <YYKit.h>

@implementation UIViewController (Common)

- (void)setupCommonView {
    
    // 左边返回按键颜色
    self.navigationController.navigationBar.tintColor = [UIColor blackColor];
    // 导航透明效果 YES 默认，NO 取笑
    self.navigationController.navigationBar.translucent = NO;
    
//    // 设置导航条的色调 理解为"混合色"
//    self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
//    // 导航栏默认是半透明状态
//    self.navigationController.navigationBar.backgroundColor = [UIColor whiteColor];
//    // 导航栏标题颜色
//    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor blackColor]}];
    
    self.bg_navAlpha = 1;
    self.bg_navColor = [UIColor whiteColor];
    self.bg_navTitleColor = [UIColor blackColor];
    
    
    // 图片设置
    UIImage *backImg = [UIImage iconWithInfo:TBCityIconInfoMake(@"\ue63d", 16, [UIColor blackColor])];
    backImg = [backImg imageByResizeToSize:CGSizeMake(22, 22) contentMode:(UIViewContentModeCenter)];
    self.navigationController.navigationBar.backIndicatorImage = backImg;
    self.navigationController.navigationBar.backIndicatorTransitionMaskImage = backImg;
    

    // 重新创建一个 barButtonItem
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc]initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:nil action:nil];
    // 设置 backBarButtonItem
    self.navigationItem.backBarButtonItem = backItem;
}

#pragma mark - 添加按钮的方法

// 自定义导航栏上的按钮
- (UIBarButtonItem *)barButtonItemWithImage:(UIImage *)image highImage:(UIImage *)highImage target:(id)target action:(SEL)action {
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.bounds = CGRectMake(0, 0, 40, 40);
    button.imageView.contentMode = UIViewContentModeCenter;
    button.adjustsImageWhenHighlighted = NO;
    [button setImage:image forState:UIControlStateNormal];
    [button setImage:highImage forState:UIControlStateHighlighted];
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    return [[UIBarButtonItem alloc] initWithCustomView:button];
}

- (UIBarButtonItem *)barButtonItemWithTitle:(NSString*)title titleColor:(UIColor*)titleColor target:(id)target action:(SEL)action {
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.bounds = CGRectMake(0, 0, 40, 40);
    button.imageView.contentMode = UIViewContentModeCenter;
    button.adjustsImageWhenHighlighted = NO;
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:titleColor forState:UIControlStateNormal];
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    return  [[UIBarButtonItem alloc] initWithCustomView:button];
}


@end

















